package servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ContextServlet3 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context3 = getServletContext();
        System.out.println(context3);//对象地址与ContextServlet2中的context2一样
        /*
        * 在ContextServlet2中已经设置了key1的值了，就已经保存下来了，再次调用键key1就可以获得对应的值value1
        * */
        System.out.println("保存之后: Context3 获取 key1的值是: " + context3.getAttribute("key1"));
    }
}
